package com.zhentao.controller;

import com.zhentao.pojo.Devices;
import com.zhentao.pojo.Scenes;
import com.zhentao.service.DevicesService;
import com.zhentao.service.ScenesService;
import com.zhentao.vo.Result;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/scenes")
public class ScenesController {

    @Resource
    private ScenesService service;
    @Resource
    private DevicesService devicesService;

//    查询场景
    @RequestMapping("/findlist")
    public Result findlist(Integer userid,String name){
        List<Scenes> findlist = service.findlist(userid,name);
        return Result.OK(findlist,"查询成功");
    }


    //   详情里的设备
    @RequestMapping("/findxiangqing")
    public Result findxiangqing(Integer scenesid){
        Scenes xiangqing = service.xiangqing(scenesid);
        return Result.OK(xiangqing,"查询成功");
    }

//    添加
    @RequestMapping("/add")
    public Result add(@RequestBody Scenes scenes){
        String add = service.add(scenes);
        return Result.OK(add,"查询成功");
    }



    //  查询设备
    @RequestMapping("/findlist1")
    public Result findList1(){
        List<Devices> all = devicesService.list();
        return Result.OK(all,"查看成功");
    }


//    删除
    @RequestMapping("/del")
    public Result del(Integer id){
        System.err.println(id);
        Integer del = service.del(id);
        return Result.OK(del,"删除成功");
    }


//
//    启动和停止
    @RequestMapping("/qidong")
    public Result del(Integer sceneid,Integer id){

        service.qidong(sceneid,id);

        return Result.OK(1,"启动成功");
    }

}
